package com.hry.store.Interceptor;

import com.hry.store.common.Const;
import com.hry.store.pojo.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 购物车结算，用户未登录的拦截
 */
@Component
public class SettleAccountInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession(true).getAttribute(Const.CURRENT_USER);
        if (null == user) {
            // 跳转到登录页面
            response.sendRedirect("/user/page/login");
        }

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}

//cas.serverUrlPrefix=http://10.245.34.158/cas/
//cas.validateServerUrlPrefix=http://10.245.34.158/cas/
//cas.redirectaddr=http://133.160.102.106